package com.example.home.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.bean.HotBean;
import com.example.home.park.HotdetailsActivity;

import java.util.List;

public class NewsHotApter extends RecyclerView.Adapter<NewsHotApter.MyHot>{
    private Context context ;
    private List<HotBean.RowsBean> list;
    private String url = "http://124.93.196.45:10001";

    public NewsHotApter(Context context, List<HotBean.RowsBean> list) {
        this.context = context;
        this.list = list;
    }

    @NonNull
    @Override
    public MyHot onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_hot,null);
        return new MyHot(view);
    }

    @Override
    public void onBindViewHolder(@NonNull MyHot holder, int position) {
        Glide.with(context).load(url+list.get(position).getCover()).into(holder.iv_hot_img);
        if(list.get(position).getTitle().length() ==10 ){
            holder.tv_hot_title.setText(list.get(position).getContent());
        }else {
            holder.tv_hot_title.setText(list.get(position).getTitle().substring(0,10)+"....");
        }
        holder.iv_hot_img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, HotdetailsActivity.class);
                intent.putExtra("listID",String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });
    }

    @Override
    public int getItemCount() {
        return 2;
    }
    class  MyHot extends RecyclerView.ViewHolder {
        ImageView iv_hot_img;
        TextView tv_hot_title;
        public MyHot(@NonNull View itemView) {
            super(itemView);
            iv_hot_img = itemView.findViewById(R.id.iv_hot_pic);
            tv_hot_title = itemView.findViewById(R.id.tv_hot_title);
        }
    }

}
